/*
 * @Author: szx
 * @Date: 2022-03-28 13:32:17
 * @LastEditTime: 2022-03-28 13:38:31
 * @Description:
 * @FilePath: \leetcode\600-699\693\693.js
 */
/**
 * @param {number} n
 * @return {boolean}
 */
var hasAlternatingBits = function (n) {
    const num = n.toString(2);
    for (let i = 1; i < num.length; i++) {
        if (num[i] ^ (num[i - 1] == 0)) return false;
    }
    return true;
};

var hasAlternatingBits = function (n) {
    const a = n ^ (n >> 1);
    return (a & (a + 1)) === 0;
};
